package com.ruix.app.mapper;

import android.util.Log;

import com.ruix.app.manager.ClientInfo;
import com.ruix.app.manager.UserManager;
import com.ruix.app.model.AppUpgradeConfig;
import com.ruix.app.model.Lesson;
import com.ruix.app.model.SystemConfig;
import com.ruix.app.model.User;
import com.ruix.app.util.LogUitl;

import org.json.JSONObject;

/**
 * Created by hadexs on 2017/4/18.
 */

public class SystemConfigMapper implements ApiMapper<SystemConfig>{

    @Override
    public SystemConfig transform(JSONObject response) {

        SystemConfig config = new SystemConfig();
        if (response != null) {
            JSONObject data = response.optJSONObject("data");
            if (data != null) {
                config.setLogin(data.optBoolean("is_login"));
                config.setFeedbackClassID(data.optString("feedback_class",""));
                JSONObject userObject = data.optJSONObject("user");
                if (userObject != null) {
                    User user = new User();
                    user.parse(userObject);
                    config.setUser(user);
                    UserManager.sharedInstance().updateUserInfo(user);
                }

                JSONObject versionObject = data.optJSONObject("version");
                if (userObject != null) {
                    AppUpgradeConfig upgradeConfig = new AppUpgradeConfig();
                    upgradeConfig.parse(versionObject);
                    config.setAppUpgradeConfig(upgradeConfig);
                }
                ClientInfo.setFeedbackClassID(config.getFeedbackClassID());
            }
        }

        return config;
    }



}
